package com.itheima.health.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{sid},#{gid})")
    void addSetmealAndGroupInfo(@Param("sid") Integer sid, @Param("gid") Integer gid);

    @Delete("delete from t_setmeal_checkgroup  where SETMEAL_ID = #{id}")
    void deleteSetmealAndcheckgroup(@Param("id") Integer id);

    @Select("select CHECKGROUP_ID from t_setmeal_checkgroup where SETMEAL_ID = #{id}")
    List<Integer> checkGroupBySetmealId(@Param("id") int id);

    //------------------------------------移动端
    //套餐详情套餐查询
    @Select("select ID,NAME,AGE,SEX,REMARK,IMG from t_setmeal where id = #{id}")
    SetmealVO selectBySetMealId(@Param("id") int id);

    //套餐详情检查组查询
    @Select("  select tcg.id ,tcg.name,tcg.remark from t_checkgroup tcg , t_setmeal_checkgroup tscg where tscg.CHECKGROUP_ID = tcg.ID and tcg.is_delete=0 and tscg.SETMEAL_ID = #{id}")
    List<CheckGroupVO> selectBySetMealIdAndGroup(@Param("id") int id);

    //套餐详情检查项查询
    @Select("select tc.NAME from t_checkitem tc,t_checkgroup_checkitem tcgc where tc.id = tcgc.CHECKITEM_ID and tc.is_delete=0 AND tcgc.CHECKGROUP_ID = #{id}")
    List<CheckItem> selectGroupAndCheckitemByGid(@Param("id") int gid);

    //套餐是否被使用查询
    @Select("select count(*) from t_order where  SETMEAL_ID = #{id} and ORDERSTATUS = '未到诊'" )
    int SelectByUser(@Param("id") Integer id);

}
